<template>
  <div>
    <el-form ref="ruleForm" :model="ruleForm" status-icon :rules="rules" label-width="100px" class="demo-ruleForm">
      <el-row>
        <!-- <el-col :xs="8" :sm="6" :md="4" :lg="3" :xl="1"><div class="grid-content bg-purple" /></el-col> -->
        <el-col :span="12">
          <el-form-item label="账号" prop="username">
            <el-input v-model="ruleForm.username" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="密码" prop="password">
            <el-input v-model="ruleForm.password" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
        <!-- <el-button @click="resetForm('ruleForm2')">重置</el-button> -->
        </el-form-item>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import { getUserInfoRequest, updateUserInfoRequest } from '@/api/employees'
export default {
  name: 'VueHr85Loginsetting',

  data() {
    return {
      ruleForm: {
        username: '',
        password: ''
      },
      rules: {
        username: [
          { required: true, message: '请输入正确的用户名', trigger: 'blur' },
          { min: 3, max: 6, message: '长度在 3到 6 个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入正确的密码', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getUserInfo()
  },
  methods: {
    async updateUserInfo() {
      try {
        const res = await updateUserInfoRequest(this.form)
        if (res.success) {
          this.$message.success('更新用户信息成功')
          this.$router.back()
        } else {
          this.$message.error('更新用户信息失败')
        }
      } catch (error) {
        console.log('updateUserInfoRequest', error)
      }
    },
    async getUserInfo() {
      try {
        const res = await getUserInfoRequest(this.$route.query?.id || '')
        console.log(res)
        this.ruleForm.username = res.data.username
        this.ruleForm.password = res.data.password
        console.log('getUserInfoRequest', res)
      } catch (error) {
        console.log('getUserInfoRequest', error)
      }
    },
    submitForm() {
      this.$refs.ruleForm.validate((val) => {
        if (val) {
          console.log(this.ruleForm)
        }
      })
    }
  }

}
</script>

<style lang="scss" scoped>

</style>
